// region 表格相关的字段

// 序号
import {var_i18n_placeText} from "../i18nUtil/i18nUtil.js";

export function var_field_index(query = {}) {
  let result = {
    label: '序号',
    prop: 'dataIndex',
    width: 60,
    fixed: 'left',
    i18Text: 'tableText.index',
    type: 'index'
  }
  Object.assign(result, query)
  return result
}

// 选择
export function var_field_choose(query) {
  let result = {
    label: '选择',
    type: 'selection',
    prop: 'dataSelection',
    width: 60,
    selectable: undefined,
    rowClick: false,
    noClick: false,
    fixed: 'left',
    i18Text: 'fieldText.choose',
    columnClass: false,
  }
  Object.assign(result, query)
  return result
}

// 更多操作
export const var_field_more = (width = 160, query = {}) => {
  let result = {
    label: '操作',
    slot: "more",
    width: width,
    fixed: 'right',
    toolTip: true,
    i18Text: 'fieldText.more',
  }
  Object.assign(result, query)
  return result
}

// 停用(插槽版本)
export const var_field_stopSlot = (query = {}) => {
  let result = {
    label: '停用状态',
    prop: 'isStop',
    slot: 'isStop',
    i18Text: 'tableText.isStop',
    width: 90
  }
  Object.assign(result, query)
  return result
}


// 停用(html版本)
export const var_field_stopHtml = (query = {}) => {
  let result = {
    label: '停用状态',
    prop: 'isStop',
    i18Text: 'tableText.isStop',
    width: 70,
    html: (row) => {
      if (row.isStop == 1) {
        return `<span style="color: red">${var_i18n_getText('tableText.stopValue1')}</span>`
      } else {
        return `<span style="color: green">${var_i18n_getText('tableText.stopValue2')}</span>`
      }
    }
  }
  Object.assign(result, query)
  return result
}

// 回显状态值方法
export const var_table_getStatus = (row, whichKey, varObj) => {
  if (row.id) {
    const key = `_${row[whichKey] || 0}`
    const value = varObj[key]
    return `<span style="color: ${value.color};">${value.label}</span>`
  } else {
    return ''
  }
}
// endregion


// region 创建者和创建时间

// 创建时间
export const var_field_createTime = (query = {}, options = {}) => {
  const i18Text = query.i18Text ? query.i18Text : 'tableText.createTime'

  const thisOptions = {
    // 搜索组件的空输入框提示
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }


  let result = {
    label: '创建时间',
    prop: 'createTime',
    i18Text: i18Text,
    width: 150,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 更新时间
export const var_field_updateTime = (query = {}, options = {}) => {

  const i18Text = query.i18Text ? query.i18Text : 'tableText.updateTime'

  const thisOptions = {
    // 搜索组件的空输入框提示
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '更新时间',
    prop: 'updateTime',
    i18Text: i18Text,
    width: 150,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 创建者
export const var_field_editor = (query = {}, options = {}) => {

  const i18Text = 'fieldText.editor'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '创建者',
    prop: 'editorName',
    width: 90,
    i18Text: i18Text,
    callBack: row => {
      if (row.editorInfo) {
        return row.editorInfo?.name
      }
    }
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 更新者
export const var_field_updateEditor = (query = {}, options = {}) => {

  const i18Text = 'tableText.updateEditorName'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '更新者',
    prop: 'updateEditorName',
    width: 90,
    i18Text: i18Text,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}


// endregion


// region 常用字段

// 名称
export const var_field_name = (query = {}, options = {}) => {

  const i18Text = 'fieldText.name'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '名称',
    prop: 'name',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
    // width: '160px',
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 编号
export const var_field_code = (query = {}, options = {}) => {

  const i18Text = 'fieldText.code'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '编号',
    prop: 'code',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 账号
export const var_field_account = (query = {}, options = {}) => {

  const i18Text = 'fieldText.account'

  const thisOptions = {
    prefixSlot: 'accountIcon',
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '账号',
    prop: 'account',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 密码
export const var_field_password = (query = {}, options = {}) => {

  const i18Text = 'fieldText.password'

  const thisOptions = {
    prefixSlot: 'passwordIcon',
    type: 'password',
    showPassword: true,
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '密码',
    prop: 'password',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}


// 手机号
export const var_field_phone = (query = {}, options = {}) => {

  const i18Text = 'fieldText.phone'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '手机号',
    prop: 'phone',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
    width: 160,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 排序
export const var_field_sort = (query = {}, options = {}) => {

  const i18Text = 'tableText.sort'

  const thisOptions = {}
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '排序',
    prop: 'sort',
    i18Text: i18Text,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 备注
export const var_field_remark = (query = {}, options = {}) => {

  const i18Text = 'fieldText.remark'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '备注',
    prop: 'remark',
    i18Text: i18Text,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 标题
export const var_field_title = (query = {}, options = {}) => {
  const i18Text = query.i18Text ? query.i18Text : 'fieldText.title'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '标题',
    prop: 'title',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 图标
export const var_field_icon = (query = {}, options = {}) => {

  const i18Text = 'fieldText.icon'

  const thisOptions = {}
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '图标',
    prop: 'icon',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: true,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 邮箱
export const var_field_email = (query = {}, options = {}) => {

  const i18Text = 'fieldText.email'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '邮箱',
    prop: 'email',
    i18Text: i18Text,
    // 搜索字段是否显示
    fixedShow: false,
    width: 150
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 值
export const var_field_value = (query = {}, options = {}) => {

  const i18Text = 'fieldText.value'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '值',
    prop: 'value',
    i18Text: i18Text,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 类型
export const var_field_type = (query = {}, options = {}) => {
  const i18Text = 'fieldText.type'

  const thisOptions = {
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '类型',
    prop: 'type',
    i18Text: i18Text,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}
// endregion


// region 表单相关的字段

// 表单的停用设置值
export const var_field_stopSwitch = (query = {}, options = {}) => {

  const i18Text = 'tableText.isStop'

  const thisOptions = {}
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '停用状态',
    prop: 'isStop',
    i18Text: i18Text,
    width: 50,
    itemWidth: 230,
    type: 'switch',
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// 输入区
export const var_field_inputTextarea = (heightParams = '120px', params = {}) => {
  const maxLength = 200
  const height = heightParams
  let result = {
    label: '备注',
    prop: 'remark',
    // 不可以调整大小
    class: 'inputTextaresNoSize',
    options: {
      type: "textarea",
      maxlength: maxLength,
      'show-word-limit': true,
      'input-style': {height: height}
    }
  }
  Object.assign(result, params)


  // region 合并后如果出现空对象
  if (result.options == undefined) {
    result.options = {
      placeholder: (item) => {
        return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
      }
    }
  }

  if (result.options.type == undefined) {
    result.options.type = "textarea"
  }

  if (result.options.maxlength == undefined) {
    result.options.maxlength = maxLength
  }
  if (result.options['show-word-limit'] == undefined) {
    result.options['show-word-limit'] = true
  }

  if (result.options['input-style'] == undefined) {
    result.options['input-style'] = {height: height}
  } else if (result.options['input-style']['height'] == undefined) {
    result.options['input-style']['height'] = height
  }
  // endregion


  return result
}

// 父级
export const var_field_parent = (query = {}, options = {}) => {

  const i18Text = 'fieldText.parentId'

  const thisOptions = {
    props: {label: 'name', value: 'id'},
    "check-strictly": true,
    placeholder: (item) => {
      return item.i18Text ? var_i18n_placeText(item.i18Text) : `请输入${item.label}`
    }
  }
  if (options != undefined) {
    Object.assign(thisOptions, options)
  }

  let result = {
    label: '父级',
    prop: 'parentId',
    type: 'tree',
    i18Text: i18Text,
  }

  Object.assign(result, query)
  result.options = thisOptions;
  return result
}

// endregion